package com.miyake.loveviewweb.shared;

import java.util.ArrayList;
import java.util.List;

import com.miyake.loveviewweb.shared.model.DataColumnModel;

public class XsvToDataColumnModel {
    private List<DataColumnModel> dataColumnModels = new ArrayList<DataColumnModel>();
    
    public XsvToDataColumnModel(String text, boolean isFirstLineHeader) {
        XsvToColumnArrayConverter converter = new XsvToColumnArrayConverter(text);
        for (List<String> ss : converter.getColumns()) {
            DataColumnModel dataColumnModel = new DataColumnModel();
            
            if (isFirstLineHeader) {
                dataColumnModel.setHeader(ss.get(0));
                ss.remove(0);
            }
            else {
                dataColumnModel.setHeader("Untitled");
            }
            
            dataColumnModel.setValue(ss.toArray(new String[0]));
            
            dataColumnModels.add(dataColumnModel);
        }
    }

    /**
     * @return the dataColumnModels
     */
    public List<DataColumnModel> getDataColumnModels() {
        return dataColumnModels;
    }

    /**
     * @param dataColumnModels the dataColumnModels to set
     */
    public void setDataColumnModels(List<DataColumnModel> dataColumnModels) {
        this.dataColumnModels = dataColumnModels;
    }
     
}
